﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data;
using System.Data.SqlClient;

namespace DAO
{
    public class GheDAO
    {
        public static List<Ghe> Select_GheTrong(Ve ve)//ghế trống
        {
            List<Ghe> list = new List<Ghe>();
            String strSql = "select MaGhe,TenGhe from Ghe gh,Xe x where x.MaXe=gh.MaXe and x.MaXe='"+ve.MaXe+"' ";
            strSql += "and MaGhe not in (select MaGhe from VeXe where MaXe='" + ve.MaXe + "' ";
            strSql += "and MaTuyenDuong='" + ve.MaTuyenDuong + "' and GioXuatBen='" + ve.GioXuatBen + "')";
            
            try
            {
                DataTable dt = SqlDataAccessHelper.ExcuteQuery(strSql);
                foreach (DataRow dr in dt.Rows)
                {
                    Ghe emp = new Ghe();
                    emp.MaGhe = dr["MaGhe"].ToString();
                    emp.TenGhe = dr["TenGhe"].ToString();
                    list.Add(emp);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return list;
        }

        public static bool Update_TinhTrang(String MaGhe,String TinhTrang)
        {
            bool result = false;
            string strSql = "update Ghe set TinhTrang=@TinhTrang where MaGhe=@MaGhe";

            try
            {
                List<SqlParameter> sqlPara = new List<SqlParameter>();
                sqlPara.Add(new SqlParameter("@MaGhe", MaGhe));
                sqlPara.Add(new SqlParameter("@TinhTrang", TinhTrang));

                int n = SqlDataAccessHelper.ExcuteNoneQuery(strSql, sqlPara);
                if (n == 1)
                    result = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }
    }
}
